package com.newtouch.bxzs.enterprise.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import com.newtouch.bxzs.enterprise.config.MyLog;
import com.newtouch.bxzs.enterprise.model.bo.*;
import com.newtouch.bxzs.enterprise.model.vo.*;
import com.newtouch.bxzs.enterprise.service.ConferenceService;
import com.newtouch.bxzs.enterprise.service.CustomerInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 营销会议controller类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021年1月18日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author Amour
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "营销会议")
@RestController
@RequestMapping(value = "/conferenceController")
@SuppressWarnings("unchecked")
public class ConferenceController {

	/** 静态变量：系统日志 */
	private static final Log logger = LogFactory.getLog(ConferenceController.class);

	@Autowired
	ConferenceService conferenceService;

	@Autowired
	CustomerInventoryService customerInventoryService;

	@ApiOperation(value = "获取营销会议信息列表")
	@PostMapping("/getConferenceList")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceList", userOperationType = 4, userOperationSummary = "获取营销会议信息列表")
	BaseResponse<IPage<ConferenceBO>> getConferenceList(@RequestBody ConferenceVO conferenceVO) {
		logger.info("获取营销会议信息列表");
		return RespGenerator.returnOK(conferenceService.getConferenceList(conferenceVO));
	}

	@ApiOperation(value = "获取营销会议详情")
	@GetMapping("/getConferenceDetail")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceDetail", userOperationType = 4, userOperationSummary = "获取营销会议详情")
	BaseResponse<ConferenceDetailBO> getConferenceDetail(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId,
			@RequestParam("managerFlag") @ApiParam(value = "是否为管理岗", required = true) Boolean managerFlag) {
		logger.info("获取营销会议详情");
		return RespGenerator.returnOK(conferenceService.getConferenceDetail(conferenceId, managerFlag));
	}

	@ApiOperation(value = "获取营销会议产品列表")
	@PostMapping("/getConferenceProduct")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceProduct", userOperationType = 4, userOperationSummary = "获取营销会议产品列表")
	BaseResponse<IPage<ConferenceActivityProductBO>> getConferenceProduct(
			@RequestBody ConferenceProductVO conferenceProductVO) {
		logger.info("获取营销会议产品列表");
		return RespGenerator.returnOK(conferenceService.getConferenceProduct(conferenceProductVO));
	}

	@ApiOperation(value = "获取营销会议客户清单")
	@PostMapping("/getConferenceCustomerList")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceCustomerList", userOperationType = 4, userOperationSummary = "获取营销会议客户清单")
	BaseResponse<IPage<ConferenceActivityCustomerBO>> getConferenceCustomerList(
			@RequestBody ConferenceCustomerVO conferenceCustomerVO) {
		logger.info("获取营销会议客户清单");
		return RespGenerator.returnOK(conferenceService.getConferenceCustomerList(conferenceCustomerVO));
	}

	@ApiOperation(value = "添加营销会议个人客户")
	@PostMapping("/addConferencePersonalCustomer")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/addConferencePersonalCustomer", userOperationType = 1, userOperationSummary = "添加营销会议个人客户")
	BaseResponse<Integer> addConferencePersonalCustomer(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId,
			@RequestParam("personalFlag") @ApiParam(value = "是否为个人客户", required = true) Boolean personalFlag,
			@RequestBody @ApiParam(value = "客户信息数组", required = true) List<CustomerDetailVO> list) {
		logger.info("添加营销会议个人客户");
		return RespGenerator
				.returnOK(conferenceService.insertConferencePersonalCustomer(conferenceId, personalFlag, list));
	}

	@ApiOperation(value = "删除营销会议个人客户")
	@PostMapping("/deleteConferencePersonalCustomer")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/deleteConferencePersonalCustomer", userOperationType = 3, userOperationSummary = "删除营销会议个人客户")
	BaseResponse<Integer> deleteConferencePersonalCustomer(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId,
			@RequestParam("customerId") @ApiParam(value = "客户ID", required = true) String customerId) {
		logger.info("添加营销会议个人客户");
		return RespGenerator.returnOK(conferenceService.deleteConferencePersonalCustomer(conferenceId, customerId));
	}

	@ApiOperation(value = "新增、修改营销会议信息")
	@PostMapping("/modifyConference")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/modifyConference", userOperationType = 5, userOperationSummary = "新增或修改营销会议信息")
	BaseResponse<String> modifyConference(@RequestBody ConferenceModifyVO conferenceModifyVO) {
		logger.info("新增、修改营销会议信息");
		return RespGenerator.returnOK(conferenceService.modifyConference(conferenceModifyVO));
	}

	@ApiOperation(value = "获取客户分配情况列表")
	@GetMapping("/getDistributionCustomerList")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getDistributionCustomerList", userOperationType = 4, userOperationSummary = "获取客户分配情况列表")
	BaseResponse<IPage<ConferenceActivityCustomerBO>> getDistributionCustomerList(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId,
			@RequestParam("currentPage") @ApiParam(value = "起始页", required = true) Integer currentPage,
			@RequestParam("pageSize") @ApiParam(value = "每页数据量", required = true) Integer pageSize,
			@RequestParam(value = "distributionFlag", required = false) @ApiParam(value = "是否查询已分配客户,不传时默认查询所有") Boolean distributionFlag) {
		logger.info("获取客户分配情况列表");
		return RespGenerator.returnOK(
				conferenceService.getDistributionCustomerList(conferenceId, distributionFlag, currentPage, pageSize));
	}

	@ApiOperation(value = "保存分配客户信息")
	@PostMapping("/modifyDistributionCustomer")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/modifyDistributionCustomer", userOperationType = 1, userOperationSummary = "保存分配客户信息")
	BaseResponse<Integer> modifyDistributionCustomer(@RequestBody DistributionCustomerVO distributionCustomerVO) {
		logger.info("保存分配客户信息");
		return RespGenerator.returnOK(conferenceService.modifyDistributionCustomer(distributionCustomerVO));
	}

	@ApiOperation(value = "参会签到")
	@GetMapping("/customerAttendance")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/customerAttendance", userOperationType = 2, userOperationSummary = "参会签到")
	BaseResponse<Integer> customerAttendance(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId,
			@RequestParam("customerId") @ApiParam(value = "客户id", required = true) String customerId,
			@RequestParam("accetptionCustomerRecordId") @ApiParam(value = "客户接收记录id", required = true) String accetptionCustomerRecordId) {
		logger.info("参会签到");
		return RespGenerator.returnOK(conferenceService.customerAttendance(conferenceId, customerId,accetptionCustomerRecordId));
	}

	@ApiOperation(value = "接收客户参会签到")
	@GetMapping("/acceptCustomerAttendance")
	String acceptCustomerAttendance(@RequestParam String conferenceId,@RequestParam String customerId){
		return conferenceService.acceptCustomerAttendance(conferenceId,customerId);
	}


	@ApiOperation(value = "取消会议")
	@GetMapping("/cancelConference")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/cancelConference", userOperationType = 2, userOperationSummary = "取消会议")
	BaseResponse<Integer> cancelConference(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId) {
		logger.info("取消会议");
		return RespGenerator.returnOK(conferenceService.cancelConference(conferenceId));
	}

	@ApiOperation(value = "删除会议")
	@GetMapping("/deleteConference")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/deleteConference", userOperationType = 3, userOperationSummary = "删除会议")
	BaseResponse<Integer> deleteConference(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId) {
		logger.info("删除会议");
		return RespGenerator.returnOK(conferenceService.deleteConference(conferenceId));
	}

	@ApiOperation(value = "查询营销会议统计信息")
	@GetMapping("/getConferenceStatistics")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceStatistics", userOperationType = 4, userOperationSummary = "查询营销会议统计信息")
	BaseResponse<ConferenceActivityStatisticsBO> getConferenceStatistics(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议id", required = true) String conferenceId) {
		logger.info("查询营销会议统计信息");
		return RespGenerator.returnOK(conferenceService.getConferenceStatistics(conferenceId));
	}

	@ApiOperation(value = "查询营销会议本端用户信息")
	@GetMapping("/getConferenceUser")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceUser", userOperationType = 4, userOperationSummary = "查询营销会议本端用户信息")
	BaseResponse<IPage<ConferenceActivityUserBO>> getConferenceUser(ConferenceUserVO conferenceUserVO) {
		logger.info("查询营销会议本端用户信息");
		return RespGenerator.returnOK(conferenceService.getConferenceUser(conferenceUserVO));
	}

	@ApiOperation(value = "查询营销会议合作公司用户信息")
	@GetMapping("/getConferenceCooperationUser")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getConferenceCooperationUser", userOperationType = 4, userOperationSummary = "查询营销会议合作公司用户信息")
	BaseResponse<IPage<ConferenceActivityUserBO>> getConferenceCooperationUser(ConferenceUserVO conferenceUserVO) {
		logger.info("查询营销会议合作公司用户信息");
		return RespGenerator.returnOK(conferenceService.getConferenceCooperationUser(conferenceUserVO));
	}

	@ApiOperation(value = "获取大数据客户清单")
	@PostMapping("/getCustomerInventory")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/getCustomerInventory", userOperationType = 4, userOperationSummary = "获取营销会议大数据客户清单")
	BaseResponse<List<CustomerInventoryBO>> getCustomerInventory(
			@RequestParam("batch") @ApiParam(value = "获取批次", required = true) Integer batch,
			@RequestBody ConferenceDetailVO conferenceDetailVO) {
		logger.info("获取大数据客户清单");
		return RespGenerator
				.returnOK(customerInventoryService.getConferenceCustomerInventory(batch, conferenceDetailVO));
	}

	@ApiOperation(value = "参加营销会议")
	@GetMapping("/joinConference")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/joinConference", userOperationType = 2, userOperationSummary = "参加营销会议")
	BaseResponse<Integer> joinConference(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议ID", required = true) String conferenceId,
			@RequestParam("userId") @ApiParam(value = "用户ID", required = true) String userId) {
		logger.info("参加营销会议");
		return RespGenerator.returnOK(conferenceService.joinConference(userId, conferenceId));
	}

	@ApiOperation(value = "推送客户")
	@PostMapping("/pushCustomer")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/pushCustomer", userOperationType = 1, userOperationSummary = "推送客户")
	BaseResponse<String> pushCustomer(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议ID", required = true) String conferenceId,
			@RequestBody CustomerDetailVO customer) {
		logger.info("推送客户");
		return RespGenerator.returnOK(conferenceService.pushCustomer(conferenceId, customer));
	}

	@ApiOperation(value = "电话联系客户")
	@PostMapping("/contactCustomer")
	@MyLog(systemFunctionName = "营销会议", systemFunctionUrl = "/conferenceController/contactCustomer", userOperationType = 2, userOperationSummary = "电话联系客户")
	BaseResponse<Integer> contactCustomer(
			@RequestParam("conferenceId") @ApiParam(value = "营销会议ID", required = true) String conferenceId,
			@RequestBody CustomerDetailVO customer) {
		logger.info("电话联系客户");
		return RespGenerator.returnOK(conferenceService.contactCustomer(conferenceId, customer));
	}

	/**
	 * 接收营销会议信息
	 * 
	 * @param conferenceAcception
	 * @return
	 */
	@PostMapping("/acceptionConference")
	@ApiIgnore
	BaseResponse<Integer> acceptionConference(@RequestBody ConferenceAcceptionVO conferenceAcception) {
		logger.info("接收营销会议信息");
		return RespGenerator.returnOK(conferenceService.acceptionConference(conferenceAcception));
	}

}
